package com.lhz.collector.common;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;

/**
 * Created by LHZ on 2017/4/12.
 */
@Component
public class DataSourceConfig {
    @Bean(name = "mysqlDataSource")
    @Qualifier("mysqlDataSource")
    @ConfigurationProperties(prefix="spring.datasource.mysql")
    public DataSource primaryDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Primary
    @Bean(name = "h2DataSource")
    @Qualifier("h2DataSource")
    @ConfigurationProperties(prefix="spring.datasource.h2")
    public DataSource secondaryDataSource() {
        return DataSourceBuilder.create().build();
    }
}
